<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/jquery-ui-1.7.3.custom.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />

		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		<script src="assets/scripts/ui/ui.dialog.js" type="text/javascript"></script>

		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<script type="text/javascript" src="./assets/scripts/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>

		<script type="text/javascript" src="./assets/scripts/search.js"></script>

		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			$('.btn_regist').click(function(){
				if( confirm('登録してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});

			$('.btn_update').click(function(){
				if( confirm('更新してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			$('.btn_return').click(function(){
				location.href = "minsshopshop_index.php?hist=2";
			});
			$('.tddel').live('click',function(){
				$(this).closest('tr').remove();
				//$('#p_count').val(get_class_sum('nper'));
				//$('#n_count').val(get_class_sum('nnum'));
			});

			$('.btn_search_muti_ins_shopw').click(function(){
				var theValue = "";
				gMutiObj = this.id;
				var urlPara = makeMutiSearchURL( gMutiObj, theValue );
				//urlPara = urlPara + "&w=" + document.fm.w.value ;
				$("#dialogmutiins").load( urlPara ).dialog({
					modal:true
				});
				$('#dialogmutiins').dialog('open');
				//iii = iii + 1;
				//li_add(this.id,iii, "inVal")
			});
		});

		function setSS( valcd, valnm ) {
			document.fm.shop_cd.value = valcd;
			document.fm.shop_name.value = valnm;
			$('#dialog').dialog("close");
		}

		function li_add( inID, inVal ,inConums ,inPattern ,inPatternnm,inAdnums ,inAmemo ,inMemo ) {
			//alert( inID.replace(/'/g, "&#39;") );
			theid = inID.replace(/'/g, "&#39;");
			theNm = inVal.replace(/'/g, "&#39;");
			if (checkNames(inID)) {
				var strHtml = '<li id="a' + inID +'" class="item_li"> <a href="#"  style="color:red" class="li_del" >X</a>&nbsp;&nbsp;'+ inID + '&nbsp;&nbsp;' + inVal;
				strHtml = strHtml + "<input type='hidden' value='" + theid + "'  name ='ins_shop_cd_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + theNm + "' name ='ins_shop_name_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inConums + "' name ='insert_conums_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inPattern + "' name ='area_pattern_cd_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inPatternnm + "' name ='area_pattern_name_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inAdnums + "' name ='area_adnums_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inAmemo + "' name ='area_memo_ul[]'>";
				strHtml = strHtml + "<input type='hidden' value='" + inMemo + "' name ='memo_ul[]'>";
				strHtml = strHtml + '</li>';
				$("#pop_ul").append(strHtml);
			}
		}
		function chkWeek() {
			var weekid = $("#matrix_cd").val() ;
			if (weekid.length == 0){
				alert("週を選択してください");
				return false;
			 }
			return true;
		}

		var g_shop_ul_to_grid = true ;
		function tr_add(vid, vname, inConums ,inPattern ,inPatternNm ,inAdnums ,inAmemo ,inMemo ) {
			var table = $('#table_insshop');
			var str = '<tr><td> <input type="text" name="ins_shop_cd[]" class="dtext"  value="'+ vid +'"  readonly/></td>'
			+ '<td> <input type="text" name="ins_shop_name[]" class="dtext"  value="'+ vname +'"  readonly/></td>'
			+ '<td> <input type="text" name="insert_conums[]" class="text"  value="'+ inConums +'"  /></td>'
			+ '<td> <select name="area_disp_ng"><option value="0" label="有効" selected>有効</option><option value="1" label="無効">無効</option>	</select></td>'
			+ '<td> <input type="text" name="area_pattern_name[]" class="dtext"  value="'+ inPatternNm +'"  readonly/>'
			+ '<input type="hidden"  name ="area_pattern_cd[]" value="'+ inPattern +'"></td>'
			+ '<td> <input type="text" name="area_adnums[]" class="text"  value="'+ inAdnums +'"  /></td>'
			+ '<td> <input type="text" name="area_memo[]" class="text"  value="'+ inAmemo +'"  /></td>'
			+ '<td> <input type="text" name="memo[]" class="text"  value="'+ inMemo +'"  /></td>'
			+ '<td> <a href="#" class="tddel tdbutton tdb2">削除</a></td></tr>';
			$(table).append(str);
		}

		function copy_shop_pop_ul_to_grid() {
			var cdsul   = document.getElementsByName( 'ins_shop_cd_ul[]');
			var cdarr   = new Array();
			$.each(cdsul, function(i,val){

				cdarr[i] = val.value;
			});
			cdsul   = document.getElementsByName( 'insert_conums_ul[]');
			var conumsarr   = new Array();
			$.each(cdsul, function(i,val){
				conumsarr[i] = val.value;
			});
			cdsul   = document.getElementsByName('area_pattern_cd_ul[]');
			var patternarr   = new Array();
			$.each(cdsul, function(i,val){
				patternarr[i] = val.value;
			});

			cdsul   = document.getElementsByName('area_pattern_name_ul[]');
			var patternnmarr   = new Array();
			$.each(cdsul, function(i,val){
				patternnmarr[i] = val.value;
			});
			cdsul   = document.getElementsByName( 'area_adnums_ul[]');
			var adnumsarr   = new Array();
			$.each(cdsul, function(i,val){
				adnumsarr[i] = val.value;
			});
			cdsul   = document.getElementsByName( 'area_memo_ul[]');
			var amemoarr   = new Array();
			$.each(cdsul, function(i,val){
				amemoarr[i] = val.value;
			});

			cdsul   = document.getElementsByName( 'memo_ul[]');
			var memoarr   = new Array();
			$.each(cdsul, function(i,val){
				memoarr[i] = val.value;
			});

			var namesul = document.getElementsByName('ins_shop_name_ul[]');
			//var html = $("#table_insshop tr:last").html();
            //html = "<tr>" + html + "</tr>";
           // $("#table_insshop tr:last").remove();
			$.each(namesul, function(i,val){
				tr_add(cdarr[i], val.value,  conumsarr[i], patternarr[i], patternnmarr[i], adnumsarr[i], amemoarr[i], memoarr[i] );
			});



			//$("#table_insshop").append(html);
		}
		</script>
	</head>
	<body id="">
{{ $menu }}
{{ $logout }}
		<div id="container"><div class="wrapper">
			<h2>販売店紐付けマスター管理</h2>
			<ul class="submenu clearfix">
				<li>販売店紐付け情報一覧</li>
			</ul>
			<h3>販売店紐付け情報{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}{{ if $phase == 'complete' }}完了{{ /if }}</h3>
{{ if $phase == 'input' }}
			<p class="message">内容を確認し、{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}ボタンをクリックしてください。</p>
			<form name="fm" action="minsshopshop_form.php?w={{$forms.w|escape}}" method="post">
				<table class="formTable">
					<tbody>
						<tr><th><span>※</span>週名/折込日</th>
							<td>
								<input type="text" name="dispw" class="dtext" value="{{ $forms.dispw|escape}}" readonly="readonly" />
								<input type="hidden" name="w"  value="{{ $forms.w|escape }}" />
							</td>
						</tr>
{{ if $forms.id != '' }}
						<tr>
							<th>更新日時</th>
							<td>
								{{ $forms.u_time|date_format:"%Y/%m/%d %H:%M" }}<input type="hidden" name="u_time" value="{{ $forms.u_time }}" />
							</td>
						</tr>
						<tr>
							<th>更新者</th>
							<td>
								{{ $forms.m_user_name }}<input type="hidden" name="m_user_name" value="{{ $forms.m_user_name }}" />
							</td>
						</tr>
						<tr>
							<th><span>※</span>店舗</th>
							<td>
								{{ $forms.shop_cd|escape }}&nbsp;&nbsp;{{ $forms.shop_name|escape }}
								<input type="hidden" name="shop_name"  value="{{ $forms.shop_name|escape }}" />
								<input type="hidden" name="shop_cd"    value="{{ $forms.shop_cd|escape }}" />
							</td>
						</tr>
{{else}}
						<tr>
							<th><span>※</span>店舗</th>
							<td>
								<input type="text" name="shop_name" class="text" value="{{ $forms.shop_name|escape }}" readonly="readonly" />
								<input type="hidden" name="shop_cd"  value="{{ $forms.shop_cd|escape }}" />
								<button type="button" id="shop" class="btn_search" rel="shop"><span>参照</span></button>
								{{ $err.shop_cd }}
							</td>
						</tr>
{{ /if }}
						<tr>
							<th><span>※</span>販売店</th>
							<td>
							<button type="button" id="ins_shop_patt" class="btn_search_muti_ins_shopw" ><span>販売店追加</span></button>
							{{ $err.insert_conums }}&nbsp;&nbsp; {{ $err.area_adnums }} <br>
<table class="formTable" id = "table_insshop" >
<tr><th ><span>GEOコード</span></th><th><span>販売店名</span></th><th><span>折込会社部数</span></th>
<th ><span>地域広告紐付</span></th><th><span>地域新聞名</span></th><th><span>地域広告部数</span></th>
<th ><span>地域広告備考</span></th><th><span>備考</span></th><th><span>操作</span></th>
</tr>
{{ foreach from=$forms.mutirow key=k item=v name="member" }}
<tr>
<td> <input type="text" name="ins_shop_cd[]" class="dtext"  value="{{ $v.ins_shop_cd }}"  readonly/></td>
<td> <input type="text" name="ins_shop_name[]" class="dtext"  value="{{ $v.ins_shop_name }}"  readonly/></td>
<td> <input type="text" name="insert_conums[]" class="nnum"  value="{{ $v.insert_conums }}"  /></td>
<td> {{ html_options name='area_disp_ng[]' options=$areaflags selected=$v.area_disp_ng separator='&nbsp;' }}</td>
<td> <input type="text" name="area_pattern_name[]" class="dtext"  value="{{ $v.area_pattern_name }}"  readonly/>
<input type="hidden" value="{{ $v.area_pattern_cd }}" name ="area_pattern_cd[]"></td>
<td> <input type="text" name="area_adnums[]" class="nnum"  value="{{ $v.area_adnums }}"  /></td>
<td> <input type="text" name="area_memo[]" class="nnum"  value="{{ $v.area_memo }}"  /></td>
<td> <input type="text" name="memo[]" class="nnum"  value="{{ $v.memo }}"  /></td>
<td> <a href="#" class="tddel tdbutton tdb2">削除</a></td>
</tr>
{{ /foreach }}
</table>
								 {{ $err.ins_shop_cd }}
							</td>
						</tr>
{{ if $forms.id != '' }}
						<tr>
							<th>非表示設定</th>
							<td style = "vertical-align:middle">
 {{ if $forms.disp_ng == '1' }}
								<label><input class="chkinput" type="checkbox" name="disp_ng" value="1" checked /> 非表示にする</label>
 {{ else }}
								<label><input class="chkinput" type="checkbox" name="disp_ng" value="1"  /> 非表示にする</label>
 {{ /if }}
							</td>
						</tr>
 {{ /if }}
					</tbody>
				</table>
				<p class="button">
				<button type="button" class="btn_return" class="submit"><span>戻る</span></button>
{{ if $forms.id != '' }}
					<button type="button" class="btn_update" class="submit"><span>更新</span></button>
{{ else }}
					<button type="button" class="btn_regist" class="submit"><span>登録</span></button>
{{ /if }}
				</p>
				<input type="hidden" name="id" value="{{ $forms.id }}" />
				<input type="hidden" name="mode" value="" />
			</form>

<div id="dialog" >
</div>
 <div id="dialogmutiins" >
</div>

{{ /if }}

{{ if $phase == 'complete' }}
			<p class="message">{{ $message }}</p>
			<ul>
{{ if $forms.id != '' }}
				<li>>> <a href="minsshopshop_index.php?hist=2">一覧ページに戻る</a></li>
{{ else }}
				<li>>> <a href="minsshopshop_index.php">一覧ページに戻る</a></li>
{{ /if }}
				<li>>> <a href="minsshopshop_form.php?w={{$forms.w|escape}}">新規登録</a></li>
{{ if $forms.id != '' }}
				<li>>> <a href="minsshopshop_form.php?id={{ $forms.id }}&w={{$forms.w|escape}}">更新</a></li>
{{ /if }}
			</ul>
{{ /if }}

		</div></div>
		{{ $footer }}
	</body>
</html>